package com.chenfan.ccp.plug.log.util;

import com.chenfan.ccp.entity.BaseUserVO;
import com.chenfan.infra.constants.CommonBeanConstants;
import org.slf4j.MDC;

import java.util.Objects;

/**
 * @author K
 * @date 2022/4/25 3:45 PM
 */
public class TenantIdUtil {

    public static String getTenantId() {
        return MDC.get(CommonBeanConstants.TENANT_ID);
    }

    public static void clearTrace() {
        MDC.clear();
    }


    private TenantIdUtil() {}

    public static String traceRequest(BaseUserVO userVO) {
        if (Objects.nonNull(userVO) && Objects.nonNull(userVO.getTenantId())) {
            MDC.put(CommonBeanConstants.TENANT_ID, userVO.getTenantId().toString());
            return userVO.getTenantId().toString();
        }
        return null;
    }
}
